package com.htu.lichen.advice;

import com.htu.lichen.exception.ProductException;
import com.htu.lichen.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: lichen
 * @Date: 12/28/20 7:08 PM
 */

@ControllerAdvice
@Slf4j
public class ProductExceptionAdvice {

    @ExceptionHandler(ProductException.class)
    @ResponseBody
    public Result<Object> exceptionHandler(ProductException exception) {
        log.error("统一异常处理", exception);
        return new Result<>(exception.getErrorCode(), exception.getMessage());
    }

}
